package com.scaffold.commons.config;

import org.apache.log4j.PropertyConfigurator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.scaffold.commons.json.JacksonUtil;
import com.scaffold.commons.web.VmUtils;


/**
 * @author wangjg
 * 
 * 系统配置。
 */
public class SysConfig extends FileConfig {
	@SuppressWarnings("unused")
	private static final Logger log = LoggerFactory.getLogger(SysConfig.class);
	
	public static String selectedPath = null;
	
	public SysConfig() {
	}
	
	/*
	 * 根据环境选择配置文件。 
	 */
	public void loadConfig() {
		String os = System.getProperty("os.name");
		if(os.indexOf("Linux")!=-1){
			configPath = "/application.remote.properties";
			selectedPath = configPath;
		}
		super.loadConfig();
		
		this.setStaticFields();
	}
	
	private void setStaticFields(){
		JacksonUtil.beautifier = this.getBoolean("json.beautifier", false);
		VmUtils.setConfig(this);
		
		String logPath = this.getString("log4j.properties");
		if(logPath!=null && logPath.length()>0){
			PropertyConfigurator.configure(logPath);	
		} 
	}

}